home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / SCHMOO.ZIP / OLECLIP.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  3KB  |  149 lines

  1. /*
  2.  * OLECLIP.C
  3.  *
  4.  * Routines to handle placing Native, ObjectLink, and OwnerLink
  5.  * information on the clipboard.
  6.  *
  7.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  8.  *
  9.  */
  10.  
  11. #ifdef MAKEOLESERVER
  12.  
  13. #include <windows.h>
  14. #include <ole.h>
  15. #include "schmoo.h"
  16. #include "oleglobl.h"
  17.  
  18.  
  19.  
  20. /*
  21.  * FOLECopyNative
  22.  *
  23.  * Purpose:
  24.  *  Allocates a memory block for Native data and places it on the clipboard,
  25.  *  assuming that the application has opened the clipboard.
  26.  *
  27.  * Parameters:
  28.  *  pOLE            LPXOLEGLOBALS containing clipboard formats.
  29.  *
  30.  * Return Value:
  31.  *  BOOL            TRUE if the data was copied, FALSE otherwise.
  32.  */
  33.  
  34. BOOL FAR PASCAL FOLECopyNative(LPXOLEGLOBALS pOLE)
  35.     {
  36.     HANDLE      hMem;
  37.  
  38.     hMem=HGetPolyline(pGlob->hWndPolyline);
  39.  
  40.     //Place Native data on clipboard.
  41.     if (NULL==hMem)
  42.         return FALSE;
  43.  
  44.     SetClipboardData(pOLE->cfNative, hMem);
  45.     return TRUE;
  46.     }
  47.  
  48.  
  49.  
  50.  
  51. /*
  52.  * FOLECopyLink
  53.  *
  54.  * Purpose:
  55.  *  Places ObjectLink OR OwnerLink information on the clipboard.
  56.  *  This function assumes that the application already has the
  57.  *  clipboard open.
  58.  *
  59.  * Parameters:
  60.  *  pOLE            LPXOLEGLOBALS containing clipboard formats.
  61.  *  fOwnerLink      BOOL indicating to set OwnerLink (TRUE)/ObjectLink (FALSE)
  62.  *  pszDoc          LPSTR to the document name.
  63.  *
  64.  * Return Value:
  65.  *  BOOL            TRUE if copying to the clipboard was successful.
  66.  *                  FALSE on any failure.
  67.  */
  68.  
  69. BOOL FAR PASCAL FOLECopyLink(LPXOLEGLOBALS pOLE, BOOL fOwnerLink, LPSTR pszDoc)
  70.  
  71.     {
  72.     HANDLE          hMem;
  73.     WORD            cf;
  74.  
  75.     //Retrieve a handle to the OwnerLink/ObjectLink format.
  76.     hMem=HLinkConstruct(rgpsz[IDS_CLASSSCHMOO], pszDoc, rgpsz[IDS_FIGURE]);
  77.  
  78.     if (NULL==hMem)
  79.         return FALSE;
  80.  
  81.     //Set one or the other format.
  82.     cf=(fOwnerLink) ? (pOLE->cfOwnerLink) : (pOLE->cfObjectLink);
  83.     hMem=SetClipboardData(cf, hMem);
  84.  
  85.     return (NULL!=hMem);
  86.     }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. /*
  94.  * HLinkConstruct
  95.  *
  96.  * Purpose:
  97.  *  Builds an ObjectLink and OwnerLink text string for OLE clipboard
  98.  *  interaction in the format of "classname\0document\0object\0\0"
  99.  *
  100.  * Parameters:
  101.  *  pszClass        LPSTR to the classname.
  102.  *  pszDoc          LPSTR to the document name.
  103.  *  pszObj          LPSTR to the object name.
  104.  *
  105.  * Return Value:
  106.  *  HANDLE          Global memory handle to an block containing
  107.  *                  the three strings with the appropriate separator.
  108.  */
  109.  
  110. HANDLE FAR PASCAL HLinkConstruct(LPSTR pszClass, LPSTR pszDoc, LPSTR pszObj)
  111.     {
  112.     HANDLE      hMem;
  113.     WORD        cch1, cch2, cch3;
  114.     LPSTR       psz;
  115.  
  116.     if (NULL==pszClass || NULL==pszDoc || NULL==pszObj)
  117.         return NULL;
  118.  
  119.     //We'll need lengths later.
  120.     cch1=lstrlen(pszClass);
  121.     cch2=lstrlen(pszDoc);
  122.     cch3=lstrlen(pszObj);
  123.  
  124.     //Extra 4 is for the null-terminators.
  125.     hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, (DWORD)(4+cch1+cch2+cch3));
  126.  
  127.     if (NULL==hMem)
  128.         return NULL;
  129.  
  130.     psz=GlobalLock(hMem);
  131.  
  132.     lstrcpy(psz, pszClass);
  133.     psz+=cch1+1;
  134.  
  135.     lstrcpy(psz, pszDoc);
  136.     psz+=cch2+1;
  137.  
  138.     lstrcpy(psz, pszObj);
  139.     *(psz+cch3+1)=0;        //Add the final null terminator.
  140.  
  141.     GlobalUnlock(hMem);
  142.     return hMem;
  143.     }
  144.  
  145.  
  146.  
  147.  
  148. #endif //MAKEOLESERVER
  149.